#ifndef DISPLAY_HPP_
#define DISPLAY_HPP_

#include <iostream>
#include <unistd.h>
#include <string>
#include <vector>

class Display
{
  private:

  public:
    virtual void Update(float, float, float) = 0;
    virtual void Print() = 0;
};

class CurrentConditionDisplay :public Display
{
  private:
    float _temp;
    float _humidity;
    float _pressure;

  public:
  CurrentConditionDisplay()
    :_temp(0), _humidity(0), _pressure(0)
  {}

  void Update(float temp, float humidity, float pressure)
  {
    _temp = temp;
    _humidity = humidity;
    _pressure = pressure;

    // 更新后应该自动显示
    Print();
    std::cout << std::endl;
  }

  void Print()
  {
    std::cout << "当前状况" << std::endl;;
    std::cout << "温度：" << _temp << "℃" << std::endl;
    std::cout << "湿度：" << _humidity << "%" << std::endl;
    std::cout << "气压：" << _pressure << "kPa" <<std::endl;
  }

  ~CurrentConditionDisplay(){}
};

class StatisticsDisplay :public Display
{
  private:
    float _aveTemp;
    float _lowTemp;
    float _highTemp;

  public:
    StatisticsDisplay()
      :_aveTemp(0), _lowTemp(0), _highTemp(0)
    {}

    void Update(float temp, float humidity, float pressure)
    {
      // ...获取平均温度、最高温度、 最低温度
      
      _lowTemp = rand() % 10 + temp;
      _highTemp = _lowTemp + rand() % 6;
      _aveTemp = (_lowTemp + _highTemp) / 2;

      Print();
      std::cout << std::endl;
    }

    void Print()
    {
      std::cout << "气象统计" << std::endl;
      std::cout << "平均温度：" << _aveTemp << "℃" << std::endl;
      std::cout << "最低温度：" << _lowTemp << "℃ " << std::endl;
      std::cout << "最高温度：" << _highTemp << "℃ " << std::endl;
    }

    ~StatisticsDisplay(){}
};

class ForecastDisplay :public Display
{
  private:
    std::vector<std::string> _forecast;

    void InitForecast()
    {
      _forecast.push_back(std::string("多云"));
      _forecast.push_back(std::string("晴"));
      _forecast.push_back(std::string("阴"));
      _forecast.push_back(std::string("暴雨"));
      _forecast.push_back(std::string("小雨"));
      _forecast.push_back(std::string("大雨"));
      _forecast.push_back(std::string("雷阵雨"));
    }

  public:
    ForecastDisplay()
    {
      InitForecast();
    }

    void Update(float temp, float humidity, float pressure)
    {
      // ...进行天气预估
      
      Print(); 
    }

    void Print()
    {
      std::cout << "天气预报" << std::endl;
      std::cout << "预计接下来的天气为：" << _forecast[rand() % _forecast.size()]<< std::endl;
    }
    
    ~ForecastDisplay(){}
};

#endif
